package chen.web;

import chen.web.user.Account;
import chen.web.user.InternalAccountProvider;


/**
 * 切换系统帐号来执行程序
 * @author chen
 *
 */
public class Executor {

	public static <T> T execute(ExecuteHandler<T> handler){
		MyContext context = MyContextProvider.getMyContext();
		//当前帐号
		Account account = context.getAccount();
		//系统帐号
		Account sysAccount = InternalAccountProvider.getSystemAccount();
		T result = null;
		//切换帐号
		try{
			context.setAccount(sysAccount);
			result = handler.handle();
		} finally{
			context.setAccount(account);
		}
		return result;
	}
	
}
